package gc3d.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class VideoBulder {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// temp vars
		int fps = 5;
		String videoname = "video.avi";
		String path = "/home/pierrick/GC3D/apache-ftpserver-1.0.0/res/home/GridPovTemp/jobtest";

		int renderreturn = -1;
		if (File.separatorChar == '/') {
			ProcessBuilder pb = new ProcessBuilder("mencoder",  
					"mf://*.png", "-mf", "fps="+fps+":type=png", "-sws", "6", 
					"-o", videoname, "-ovc", "xvid", "-xvidencopts", "fixed_quant=7");
			pb.redirectErrorStream(true);
			pb.directory(new File(path));
			Process p;
			try {
				System.out.println("pb.start");
				p = pb.start();
				// Here: POV-Ray is runing
				System.out.println("started");
				// we have to read the buffer to do not get pipe overflow (make the pipe full)
				InputStream is = p.getInputStream();
				InputStreamReader isr = new InputStreamReader(is);
				BufferedReader br = new BufferedReader(isr);
				String buff;
				while ((buff = br.readLine()) != null)
					System.out.println(buff);
				renderreturn = p.waitFor(); // should be 0
				System.out.println("finish");
			} catch (IOException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
